﻿using System.ComponentModel;
using System.IO;
using System.Net.Mime;
using Baik.Execution;
using Baik.Expression;
using Baik.Interface.Execution;
using Baik.Interface.Expression;
using Baik.Interface.Framework;
using Baik.Interface.Token;
using Baik.Token;

namespace Baik
{
    public class BaikInstance
    {
        public IInjector Injector { get; set; }
        
        public IExecutionEnvironment Environment { get; set; }
        public IScope Global { get; set; }
        public BaikInstance()
        {
            Injector = new Injector();
            Injector.Run(new TokenRegistrationScript());
            Injector.Run(new ExpressionRegistrationScript());
            Injector.Run(new ExecutionRegistrationScript());
            Environment = Injector.Instantiate<IExecutionEnvironment>();
            Global = Injector.Instantiate<IObject>();
            Environment.Load(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), "init.baik"));
            Environment.Load("init.baik");
        }

        
        public IExpression Parse(string code)
        {
            return Environment.Parse(code);
        }
        public IObject Evaluate(IExpression exp)
        {
            return exp.Evaluate(Global);
        }
        public IObject Evaluate(string code)
        {
            return Environment.Eval(code);
        }
    }
}